#include "park.h"
#include <QSqlQuery>
#include <QVariant>
#include <QDebug>
park::park(QSqlQuery query)
{
    this->query=query;
}
void park::set_id(int id){
    this->id=id;
}
int park::get_id(){
    return id;
}

void park::get_position(int the_id){
    this->query.exec(QString("select * from place where id='%1'").arg(the_id));
    query.next();
    int x=this->query.value("x").toInt();
    int y=this->query.value("y").toInt();
    this->x=x;
    this->y=y;
}
int park::get_x(){
    return this->x;
}
int park::get_y(){
    return this->y;
}
QString park::countroute(int x,int y,int the_id){
    QString s="(0,0)->";
    if(x==0){
        s+=QString("(0,1)->");
    }
    else{
        int j=1;
        for(j=1;j<y;j++){
             s+=QString("(0,%1)->").arg(j);
        }
    }
    int i;
    for(i=1;i<=x;i++){
        s+=QString("(%1,%2)->").arg(i).arg(y-1);
    }
    s+=QString("(%1,%2)").arg(x).arg(y);
    this->query.exec(QString("update place set status=1 where id='%1'").arg(the_id));
    return s;
}
QString park::text(int x,int y,int the_id){
    QString s="";
    if(y==0){
        s+= QString("-----向东走1个单位-----》");
    }
    else s+=QString("-----向东走%1个单位-----》").arg(y-1);
    s+=QString("-----向南走%1个单位-----》").arg(x);
    return s;
}
